﻿

Public Module extentions_richtextbox
    <System.Runtime.CompilerServices.Extension()> _
    Public Function GetText(richTextBox As RichTextBox) As String
        ' use a TextRange to fish out the Text from the Document
        Dim textRange As New TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd)
        Return textRange.Text.Replace(Environment.NewLine, "")
    End Function

    <System.Runtime.CompilerServices.Extension()> _
    Public Sub appendTixt(ByVal rtbx As RichTextBox, ByVal str As String)
        rtbx.AppendText(str)
        rtbx.ScrollToEnd()
    End Sub

    <System.Runtime.CompilerServices.Extension()> _
    Public Sub addTextPair(rtbx As RichTextBox, item As String, value As String)
        'prefixe
        Dim block_prefix As New Run(item)
        block_prefix.Foreground = Windows.Media.Brushes.DarkGray
        block_prefix.FontWeight = FontWeights.Bold
        'suffixe
        Dim block_dossierDest As New Run(value)
        'ajout au paragraph
        Dim para As New Paragraph()
        para.Inlines.Add(block_prefix)
        para.Inlines.Add(block_dossierDest)
        para.Margin = New Thickness(0)
        'ajout au richtextbox
        rtbx.Document.Blocks.Add(para)
    End Sub

    <System.Runtime.CompilerServices.Extension()> _
    Public Sub addTextTitle(rtbx As RichTextBox, txt As String)
        'prefixe
        Dim block_prefix As New Run(txt)
        block_prefix.Foreground = Windows.Media.Brushes.Black
        block_prefix.FontWeight = FontWeights.Bold
        block_prefix.TextDecorations = TextDecorations.Underline
        'ajout au paragraph
        Dim para As New Paragraph()
        para.Inlines.Add(block_prefix)
        para.Margin = New Thickness(0)
        'ajout au richtextbox
        rtbx.Document.Blocks.Add(para)
    End Sub
End Module